import axios from 'axios';
import {useRouter} from "vue-router";
const router = useRouter();

const instance = axios.create({
    baseURL: 'http://localhost:8080/api',
    timeout: 1000 * 12
});

// 传参默认开启cookies
instance.defaults.withCredentials = true

// 请求拦截器
instance.interceptors.request.use((config) => {
        return config;
    }, (error) => {
        console.log(error);
    },
);

// 响应拦截器
instance.interceptors.response.use(async (res) => {
    const result = await res.data.code;
    // if(result === 40100){
    //     alert("未登录，请先登录");
    // }
    return res;
}, (error) => {
    return Promise.reject(error);
});

export default instance;